package cn.wolfcode.shop.result;

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

/**
 * 用来存放各种异常信息的类
 */
@Getter
@Setter
public class CodeMsg implements Serializable{

    private int code;//自定义的后台处理的响应码
    private String msg;//后台响应的信息
    //private T data;
    private CodeMsg(int code,String msg){
        this.code = code;
        this.msg = msg;
    }

    public static final CodeMsg SUCCESS = new CodeMsg(200,"%s");;
    //对于系统异常消息 500xx开头的
    public static final CodeMsg SERVER_ERROR = new CodeMsg(500001,"系统异常");
    public static final CodeMsg ILLEAGE_OP = new CodeMsg(500002,"非法操作");
    public static final CodeMsg SECKILL_FAILED = new CodeMsg(500003,"秒杀失败");
    public static final CodeMsg NEED_LOGIN = new CodeMsg(500004,"请先登录");
    public static final CodeMsg ACCESS_LIMIT = new CodeMsg(500005,"访问过于频繁,请稍后再试");
    //用户模块异常信息5001xx
    public static final CodeMsg MOBILE_EMPTY = new CodeMsg(500101,"手机号码不能为空");
    public static final CodeMsg PASSWORD_EMPTY = new CodeMsg(500102,"密码不能为空");
    public static final CodeMsg MOBILE_INVALID = new CodeMsg(500103,"手机号码格式错误");
    public static final CodeMsg ACCOUNT_NOT_EXIST = new CodeMsg(500104,"该账号为注册");
    public static final CodeMsg LOGIN_FAIL = new CodeMsg(500105,"账号或者密码不正确");
    public static final CodeMsg PARAM_ERROR = new CodeMsg(500106,"参数异常:%s");
    public static final CodeMsg TOKEN_INVALID = new CodeMsg(500107,"登录信息已失效");
    public static final CodeMsg ORDER_NULL = new CodeMsg(500109,"订单异常");
    //秒杀模块 5002xx开头
    public static final CodeMsg SECKILL_OVER = new CodeMsg(500201,"秒杀活动已结束");
    public static final CodeMsg REPEAT_SECKILL_OP = new CodeMsg(500202,"已成功秒杀,不能重复秒杀");
    public static final CodeMsg SECKILL_ERROR = new CodeMsg(500203,"秒杀错误");
    public static final CodeMsg VERIFYCODE_ERROR = new CodeMsg(500204,"验证码错误,请重新输入");
    public CodeMsg fillArgs(Object... args) {
        CodeMsg codeMsg = new CodeMsg(this.getCode(),this.getMsg());
        codeMsg.setMsg(String.format(codeMsg.getMsg(),args));
        return codeMsg;
    }
}
